<template>
	<view class="content upde-info">
		<view class="input-group">
			<view class="input-row border">
				<label class="title"><span class="i-color">* </span>建筑项目名称</label>
				<input type="text" class="input-text uni-input uni-view" v-model="data.projectName" placeholder="请输入建筑项目名称"></input>
			</view>
			<view class="input-row border">
				<label class="title">建筑面积（m²）</label>
				<input type="text" class="input-text uni-view" v-model="data.mianji" placeholder="请输入建筑面积（m²）" />
			</view>
			<view class="input-row border">
				<label class="title">建筑项目地址</label>
				<input type="text" class="input-text uni-view" v-model="data.address" placeholder="请输入建筑项目地址" />
			</view>
			<view class="input-row border">
				<label class="title">开工日期</label>
				<input type="text" class="input-text uni-view" v-model="data.kaigongDate" placeholder="请输入建筑项目地址" />
			</view>
			<view class="input-row border">
				<label class="title">经纬度</label>
				<input type="text" class="input-text uni-view" v-model="data.jingweidu" placeholder="请输入经纬度" />
			</view>
			<view class="input-row border">
				<label class="title">竣工时间</label>
				<input type="text" class="input-text uni-view" v-model="data.jungongDate" placeholder="请输入竣工时间" />
			</view>
			<view class="input-row border">
				<label class="title">图审意见书编号</label>
				<input type="text" class="input-text uni-view" v-model="data.yjscode" placeholder="请输入图审意见书编号" />
			</view>
			<view class="input-row border">
				<label class="title"><span class="i-color">* </span>建筑单位名称</label>
				<input type="text" class="input-text uni-view" v-model="data.testName" placeholder="请输入建筑单位名称"></input>
			</view>
			<view class="input-row border">
				<label class="title">建筑单位联系人</label>
				<input type="text" class="input-text uni-view" v-model="data.linkMan" placeholder="请输入建筑单位联系人"></input>
			</view>
			<view class="input-row border">
				<label class="title">联系电话</label>
				<input type="text" class="input-text uni-view" v-model="data.linkPhone" placeholder="请输入联系电话"></input>
			</view>
			<view class="input-row border">
				<label class="title">设计单位名称</label>
				<input type="text" class="input-text uni-view" v-model="data.shejiOrg" placeholder="请输入设计单位名称"></input>
			</view>
			<view class="input-row border">
				<label class="title">设计单位联系人</label>
				<input type="text" class="input-text uni-view" v-model="data.shejiMan" placeholder="请输入设计单位联系人"></input>
			</view>
			<view class="input-row border">
				<label class="title">联系电话</label>
				<input type="text" class="input-text uni-view" v-model="data.shejiPhone" placeholder="请输入联系电话"></input>
			</view>
			<view class="input-row border">
				<label class="title">施工单位名称</label>
				<input type="text" class="input-text uni-view" v-model="data.shigongOrg" placeholder="请输入施工单位名称"></input>
			</view>
			<view class="input-row border">
				<label class="title">施工单位联系人</label>
				<input type="text" class="input-text uni-view" v-model="data.shigongMan" placeholder="请输入施工单位联系人"></input>
			</view>
			<view class="input-row border">
				<label class="title">联系电话</label>
				<input type="text" class="input-text uni-view" v-model="data.shigongPhone" placeholder="请输入联系电话"></input>
			</view>
			<view class="input-row border">
				<label class="title">监理单位名称</label>
				<input type="text" class="input-text uni-view" v-model="data.jianliOrg" placeholder="请输入监理单位名称"></input>
			</view>
			<view class="input-row border">
				<label class="title">监理单位联系人</label>
				<input type="text" class="input-text uni-view" v-model="data.jianliMan" placeholder="请输入建筑单位联系人"></input>
			</view>
			<view class="input-row border">
				<label class="title">联系电话</label>
				<input type="text" class="input-text uni-view" v-model="data.jianliPhone" placeholder="请输入联系电话"></input>
			</view>
			<view  class="input-row border">
				<text class="title">相关附件:</text>
				<view class="uni-uploader" style="padding:15upx;">
					<view class="uni-uploader__input-box" v-if="img.length<5" @tap="chooseImage"></view>
				</view>
			</view >
			<view v-if="img.length>0" class="img-box-wrapper">
				<view class="img-box" v-for="(item,key) in img" :key="key" >
					<image class="uni-uploader__img"  src="/static/question_bank.png"></image>
					<view class="icon-box" @click="deleteImg(key)">
						<icon type="clear" size="26" />
					</view>
				</view>
			</view> 
		</view>
		<view class="btn-row">
			<button type="primary" class="primary" @tap="update">提交</button>
		</view>
	</view>
</template>


<script>
	import api from '../../api.js';

	export default {
		components: {
		},
		data() {
			return {
				img:[],
				data:{
					createUser:uni.getStorageSync('token'),
					testName:'',
					linkOrg:'',
					linkMan:'',
					linkPhone:'',
					address:'',
					testAddress:'',
					tester:'',
					fltype:'',
					type:1,
					state:0,
					files:''
				}
			}
		},
		onLoad: function(e) {
			var mydate=new Date();
			this.data.files="cms"+mydate.getDay()+ mydate.getHours()+ mydate.getMinutes()+mydate.getSeconds()+mydate.getMilliseconds()+ Math.round(Math.random() * 10000);
		},
		methods: {

			// 删除图片
			deleteImg(key) {
				this.img.splice(key,1);
			},
			chooseImage() {
				var _this=this;
				plus.gallery.pick( function(path){
					if(!path)return false;
					if(_this.img.length>=5)return false;
					uni.showLoading({
						title: '上传中',
						mask:true
					});
					api.uploadFile({
						url: 'core/file/uploadAttachment.json',
						filePath: path,
						name: 'file',
						formData:{
							batchFileUUID:_this.data.files,
						},
						success: (data) => {
							uni.hideLoading();
							if (data.code == 0) {
								_this.img.push(data.data.id);
							} else {
								uni.showToast({
									icon: 'none',
									title: '上传失败，请重新上传'
								});
							}
						},
						fail() {
							uni.hideLoading();
							uni.showToast({
								icon: 'none',
								title: '上传失败，请重新上传'
							});
						}
					})
				}, function ( e ) {
					console.log( "取消选择图片" );
				}, {filter:"none"} );
			},
			// 修改
			update() {
				if (this.data.projectName.length < 2) {
					return uni.showToast({
						icon: 'none',
						title: '请输入建筑项目名称'
					});
				}
				if (this.data.testName.length < 2) {
					return uni.showToast({
						icon: 'none',
						title: '请输入建筑单位名称'
					});
				}
				   uni.showLoading({
				   	title: '保存中',
				   	mask:true
				   });
				api.post({
					url: 'api/addTest.do',
					data: this.data,
					success(res) {
						uni.hideLoading();
						if(res.code!=0){
							return uni.showToast({
								icon: 'none',
								title: res.msg,
							});
						}else{
							uni.showToast({
								icon: 'none',
								title: '提交成功，等待审核！'
							});
							setTimeout(function(){
								uni.navigateBack({
									delta: 2
								})
							},1000)
						}
						
						
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.input-row .title {
		font-size: 28upx;
		width: 200upx;
		height: 40upx;
		min-height: 40upx;
		padding: 20upx 0 20upx 20upx;
		line-height: 40upx;
	}
	.upde-info{
		.input-row.border:last-of-type::after{
			height: 0;
		}
		.uni-radio-wrapper{
			.uni-radio-input{
				width: 40upx;
				height: 40upx;
			}
		}
		.picker-item{
			flex: 1;
			.uni-view{
				text-align: left;
			}
		}
	}
	.input-row{		
		.uni-view{
			&.placehold-view{
				color: #808080;
			}
		}
		.radio-group{
			flex: 1;
		}
		.input-text{
			flex: 1;
			min-height: 40upx;
			height: 40upx;
			line-height: 40upx;
			font-size: 28upx;
			padding: 20upx 0;
		}
		.textarea-text {
			flex: 1;
			border: 1px solid #B2B2B2;
			margin: 10upx 10upx 10upx 16upx;
			padding: 10upx;
			font-size: 28upx;
			line-height: 40upx;
			height: 200upx;
		}
	}
	uni-input, uni-input input{
		min-height: 80upx;
	}
	.radio-group {
		height: 40upx;
		.radio{
			margin-right: 20upx;
		}
	}
	
	.img-box-wrapper{
		.img-box {
			width: 160upx;
			height: 160upx;
			position: relative;
			font-size: 0;
			margin: 0 20upx 20upx 0;
			.img {
				width: 160upx;
				height: 160upx;
			}
			.icon-box {
				position: absolute;
				right: 0;
				top: 0;
				transform: translate(50%, -50%);
				background: #fff;
				border-radius: 50%;
				icon {
					float: left;
				}
			}
		}
	}
</style>